home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 10 / FM Towns Free Software Collection 10.iso / ms_dos / lib / happysrc / pcinsmbl.c < prev    next >
Text File  |  1994-10-01  |  27KB  |  694 lines

  1. /*********************************************************************
  2.  *
  3.  *      ***  HAPPy Pascal compiler ***
  4.  *          input symbol routine
  5.  *
  6.  *               void insymbol(void)
  7.  *               void real_err(int sig, int subcode)
  8.  *
  9.  *            copyright(c) H.Asano  1992-1994.
  10.  *
  11.  *              return item -----
  12.  *                sy   : 要素のsymbol
  13.  *                op   : 要素の演算子タイプ
  14.  *                id   : 名標
  15.  *                ch   : 読込文字
  16.  *                lgth : 文字列等の長さ
  17.  *                val  : 数値
  18.  *
  19.  *********************************************************************/
  20.  
  21. #define EXTERN extern
  22.  
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <jctype.h>
  27. #include "pascomp.h"
  28. #include "pcpcd.h"
  29.  
  30. /***** function prototype define ******/
  31.  
  32. extern void genp(enum pcdmnc, int) ;
  33. extern void pcerr(int,char*);
  34. extern char *inttoch(long)  ;
  35. extern void term(void) ;
  36. extern void *Malloc(int) ;
  37. static void skipspace(void);
  38. static void nextch(void);
  39. static void identifier(void);
  40. static void innumber(void) ;
  41. static long chtoint(int,char*) ;
  42. static void strings(void) ;
  43. static void colonch(void);
  44. static void lparch(void);
  45. static void rparch(void);
  46. static void periodch(void);
  47. static void ltch(void);
  48. static void gtch(void);
  49. static void skipcomment(void);
  50. static void options(void)  ;
  51. static void specialch(void);
  52. static void illegch(void);
  53.  
  54.  
  55. /*****************************/
  56. /****      共通変数       ****/
  57. /*****************************/
  58.  
  59. extern FILE   *passource;  /* pascal ソースファイルポインタ */
  60.  
  61. /*****************************/
  62. /****      内部変数       ****/
  63. /*****************************/
  64.  
  65.  
  66. /***** pascal 予約語テーブル *****/
  67. static struct _reswd {
  68.        char          rw[10] ;           /* 予約語           */
  69.        enum symbol   rsy   ;            /* 予約語のsymbol   */
  70.        enum operator rop   ;            /* 予約語中の演算子 */
  71.     }  reswd[]  =     {
  72. /*lngh entno  (for frw table) */
  73. /*  2 *   0 */  {"if"       , ifsy     , noop },
  74. /*    *   1 */  {"do"       , dosy     , noop },
  75. /*    *   2 */  {"of"       , ofsy     , noop },
  76. /*    *   3 */  {"to"       , tosy     , noop },
  77. /*    *   4 */  {"in"       , relop    , inop },
  78. /*    *   5 */  {"or"       , addop    , orop },
  79. /*  3 *   6 */  {"end"      , endsy    , noop },
  80. /*    *   7 */  {"for"      , forsy    , noop },
  81. /*    *   8 */  {"var"      , varsy    , noop },
  82. /*    *   9 */  {"div"      , mulop    , idiv },
  83. /*    *  10 */  {"mod"      , mulop    , imod },
  84. /*    *  11 */  {"set"      , setsy    , noop },
  85. /*    *  12 */  {"and"      , mulop    , andop},
  86. /*    *  13 */  {"not"      , notsy    , noop },
  87. /*    *  14 */  {"nil"      , nilsy    , noop },
  88. /*  4 *  15 */  {"then"     , thensy   , noop },
  89. /*    *  16 */  {"else"     , elsesy   , noop },
  90. /*    *  17 */  {"with"     , withsy   , noop },
  91. /*    *  18 */  {"goto"     , gotosy   , noop },
  92. /*    *  19 */  {"case"     , casesy   , noop },
  93. /*    *  20 */  {"type"     , typesy   , noop },
  94. /*    *  21 */  {"file"     , filesy   , noop },
  95. /*  5 *  22 */  {"begin"    , beginsy  , noop },
  96. /*    *  23 */  {"until"    , untilsy  , noop },
  97. /*    *  24 */  {"while"    , whilesy  , noop },
  98. /*    *  25 */  {"array"    , arraysy  , noop },
  99. /*    *  26 */  {"const"    , constsy  , noop },
  100. /*    *  27 */  {"label"    , labelsy  , noop },
  101. /*  6 *  28 */  {"repeat"   , repeatsy , noop },
  102. /*    *  29 */  {"record"   , recordsy , noop },
  103. /*    *  30 */  {"downto"   , downtosy , noop },
  104. /*    *  31 */  {"packed"   , packedsy , noop },
  105. /*  7 *  32 */  {"program"  , progsy   , noop },
  106. /*  8 *  33 */  {"function" , funcsy   , noop },
  107. /*  9 *  34 */  {"procedure", procsy   , noop }
  108. } ;
  109.  
  110. static int frw[] = {0,0,6,15,22,28,32,33,34,35,35};
  111.     /*  予約語の長さで、予約語テーブルのサーチを高速化している */
  112.  
  113. /***** 読込み対象JISコード256種類を分類するためのテーブル *****/
  114.  
  115. enum  chtp {
  116.       letter,     /* 英字             */
  117.       number,     /* 数字             */
  118.       special,    /* 特殊文字         */
  119.       illegal,    /* 許されないコード */
  120.       chstrquo,   /* コーテーション   */
  121.       chcolon,    /* :  コロン        */
  122.       chperiod,   /* . ピリオド       */
  123.       chlt,       /* <  less than     */
  124.       chgt,       /* >  grater than   */
  125.       chlparen,   /* (  左かっこ      */
  126.       chrparen,   /* )  右かっこ      */
  127.       chcoment,   /* {  注釈開始      */
  128.       chspace     /* 空白             */
  129. } ;
  130. static struct  {
  131.        enum chtp     chartp    ;      /* 文字のタイプ  */
  132.        enum symbol   ssy       ;      /* 文字のsymbol  */
  133.        enum operator sop       ;      /* 文字中の演算子*/
  134.     }  chartb[256]  =    {
  135.  
  136.  /****** 00-1F : 制御コード  HT(09),LF(0A)はspace  それ以外はillegal *******/
  137.  /*00-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  138.  /*03-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  139.  /*06-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  140.  /*09-*/{chspace,othersy,noop}, {chspace,othersy,noop}, {illegal,othersy,noop},
  141.  /*0C-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  142.  /*0F-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  143.  /*12-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  144.  /*15-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  145.  /*18-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  146.  /*1B-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  147.  /*1E-*/{illegal,othersy,noop}, {illegal,othersy,noop},
  148.  
  149.    /****** 20-2F : 各種文字 ******/
  150.  /* sp  (20) */    {chspace,othersy,noop},
  151.  /* !   (21) */    {illegal,othersy,noop},
  152.  /* "   (22) */    {illegal,othersy,noop},
  153.  /* #   (23) */    {illegal,othersy,noop},
  154.  /* $   (24) */    {special,othersy,noop},
  155.  /* %   (25) */    {illegal,othersy,noop},
  156.  /* &   (26) */    {illegal,othersy,noop},
  157.  /* '   (27) */    {chstrquo,othersy,noop},
  158.  /* (   (28) */    {chlparen,lparent,noop},
  159.  /* )   (29) */    {chrparen,rparent,noop},
  160.  /* *   (2A) */    {special,mulop,mul},
  161.  /* +   (2B) */    {special,addop,plus},
  162.  /* ,   (2C) */    {special,comma,noop},
  163.  /* -   (2D) */    {special,addop,minus},
  164.  /* .   (2E) */    {chperiod,period,noop},
  165.  /* /   (2F) */    {special,mulop,rdiv},
  166.  
  167.    /****** 30-39: 数字 ******/
  168.  /*012*/ {number,othersy,noop}, {number,othersy,noop}, {number,othersy,noop},
  169.  /*345*/ {number,othersy,noop}, {number,othersy,noop}, {number,othersy,noop},
  170.  /*678*/ {number,othersy,noop}, {number,othersy,noop}, {number,othersy,noop},
  171.  /*9  */ {number,othersy,noop},
  172.  
  173.    /****** 3A-40 : 各種文字 ******/
  174.  /* :   (3A) */    {chcolon,colon,noop},
  175.  /* ;   (3B) */    {special,semicolon,noop},
  176.  /* <   (3C) */    {chlt,relop,ltop},
  177.  /* =   (3D) */    {special,relop,eqop},
  178.  /* >   (3E) */    {chgt,relop,gtop},
  179.  /* ?   (3F) */    {illegal,othersy,noop},
  180.  /* @   (40) */    {special,arrow,noop},  /* ^ の 代用 */
  181.  
  182.    /****** 41-5A : 英大文字 ******/
  183.  /*ABC*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  184.  /*DEF*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  185.  /*GHI*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  186.  /*JKL*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  187.  /*MNO*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  188.  /*PQR*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  189.  /*STU*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  190.  /*VWX*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  191.  /*YZ */ {letter,othersy,noop}, {letter,othersy,noop},
  192.  
  193.    /****** 5B-60 : 各種文字 ******/
  194.  /* [   (5B) */    {special,lbrack,noop},
  195.  /* \   (5C) */    {illegal,othersy,noop},
  196.  /* ]   (5D) */    {special,rbrack,noop},
  197.  /* ^   (5E) */    {special,arrow,noop},
  198.  /* _   (5F) */    {illegal,othersy,noop},
  199.  /* `   (60) */    {illegal,othersy,noop},
  200.  
  201.   /****** 61-7A : 英小文字 ******/
  202.  /*abc*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  203.  /*def*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  204.  /*ghi*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  205.  /*jkl*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  206.  /*mno*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  207.  /*pqr*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  208.  /*stu*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  209.  /*vwx*/ {letter,othersy,noop}, {letter,othersy,noop}, {letter,othersy,noop},
  210.  /*yz */ {letter,othersy,noop}, {letter,othersy,noop},
  211.  
  212.    /****** 7B-7F : 各種文字 ******/
  213.  /* {   (7B) */    {chcoment,othersy,noop},
  214.  /* |   (7C) */    {illegal, othersy,noop},
  215.  /* }   (7D) */    {illegal, othersy,noop},
  216.  /*(7E-7F)*/       {illegal, othersy,noop}, {illegal,othersy,noop},
  217.  
  218.    /***** 80-FF : 各種記号 & カタカナ ******/
  219.  /*80-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  220.  /*83-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  221.  /*86-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  222.  /*89-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  223.  /*8C-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  224.  /*8F-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  225.  /*92-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  226.  /*95-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  227.  /*98-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  228.  /*9B-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  229.  /*9E-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  230.  /*A1-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  231.  /*A4-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  232.  /*A7-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  233.  /*AA-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  234.  /*AD-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  235.  /*B0-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  236.  /*B3-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  237.  /*B6-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  238.  /*B9-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  239.  /*BC-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  240.  /*BF-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  241.  /*C2-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  242.  /*C5-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  243.  /*C8-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  244.  /*CB-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  245.  /*CE-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  246.  /*D1-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  247.  /*D4-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  248.  /*D7-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  249.  /*DA-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  250.  /*DD-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  251.  /*E0-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  252.  /*E3-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  253.  /*E6-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  254.  /*E9-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  255.  /*EC-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  256.  /*EF-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  257.  /*F2-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  258.  /*F5-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  259.  /*F8-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  260.  /*FB-*/{illegal,othersy,noop}, {illegal,othersy,noop}, {illegal,othersy,noop},
  261.  /*FE-*/{illegal,othersy,noop}, {illegal,othersy,noop}
  262.  };
  263.  
  264. static boolean eolnflag    = true  ;    /* EOLN検出時 true            */
  265. static boolean period2flag = false ;    /* 数字処理中 ".." 検出時 true*/
  266. static boolean rbrackflag  = false ;    /* 数字処理中 ".)" 検出時 true*/
  267.  
  268. /*************************************************************************/
  269.  
  270. /**************************************/
  271. /*   insymbol() : symbolの読込メイン  */
  272. /**************************************/
  273.  
  274. void insymbol(void)
  275. {
  276.      skipspace() ;                      /* 空白読み飛ばし             */
  277.      switch(chartb[ch].chartp) {
  278.        case letter  : identifier()  ;  break; /* 名前の  処理         */
  279.        case number  : innumber()    ;  break; /* 数字の  処理         */
  280.        case chstrquo: strings()     ;  break; /* 文字列  処理         */
  281.        case chcolon : colonch()     ;  break; /* : の    処理         */
  282.        case chperiod: periodch()    ;  break; /* . の    処理         */
  283.        case chlt    : ltch()        ;  break; /* < の    処理         */
  284.        case chgt    : gtch()        ;  break; /* > の    処理         */
  285.        case chlparen: lparch()      ;  break; /* ( の    処理         */
  286.        case chrparen: rparch()      ;  break; /* ) の    処理         */
  287.        case chcoment: skipcomment() ;  break; /* 注釈の  処理         */
  288.        case special : specialch()   ;  break; /* 特殊文字処理         */
  289.        case illegal : illegch()     ;  break; /* 不当文字処理         */
  290.     /* case chspace :                   ---> このcase分岐はあり得ない */
  291.      };
  292. }
  293.  
  294. /**************************************/
  295. /*  skipspace() : 空白読み飛ばし      */
  296. /**************************************/
  297. static void skipspace(void)
  298. {
  299.      while(chartb[ch].chartp == chspace)
  300.       nextch();
  301. }
  302.  
  303. /**************************************/
  304. /*    nextch() : 次の1字読込処理      */
  305. /**************************************/
  306. static void nextch(void)
  307. {
  308.   static boolean eofflag  = false ;     /* EOF検出時  true            */
  309.   int lch ;
  310.  
  311.      if(eofflag) {
  312.       pcerr(610,"") ;                   /* EOF検出                    */
  313.       term() ;                          /* 終了処理                   */
  314.      }
  315.  
  316.      if(eolnflag) {                    /* 前の文字が行の終わりだった時*/
  317.       lineno++;
  318.       do ;
  319.        while((lch=getc(passource)) == ' '); /* 空白読み飛ばし         */
  320.      }
  321.  
  322.      if(!eolnflag) lch = getc(passource) ;
  323.  
  324.      eofflag  = feof(passource) ;
  325.      eolnflag = (lch == '\n') ;
  326.      ch = (eofflag)                     /* EOFの時は  読込文字を空白  */
  327.            ? ' ' : lch ;
  328.  
  329. }
  330.  
  331. /**************************************/
  332. /*     identifier() : 名前の処理      */
  333. /**************************************/
  334. static void identifier(void)
  335. {
  336.   int k=0;
  337.   int i;
  338.   enum chtp wktype ;
  339.  
  340.      for(i=0;i<=MaxIDlng;i++)          /* null クリア                */
  341.       id[i]='\0';
  342.                              /***** 高速化のためにポインタを使う  *****/
  343.      do {
  344.       if(k<MaxIDlng)                    /* 最大識別長まで格納         */
  345.        *(id+k++)=(('A'<=ch) && (ch<='Z'))  ? (char)ch+' ' : (char)ch ;
  346.                                         /* 大文字を小文字に変換       */
  347.       nextch();
  348.       } while(((wktype=(*(chartb+ch)).chartp) == letter) ||
  349.           ( wktype                        == number)) ;
  350.  
  351.       for(i=*(frw+k-1); i<*(frw+k);i++) { /* 予約語テーブルサーチ     */
  352.        if(!strcmp(id,(*(reswd+i)).rw)) {  /* 予約語である時           */
  353.     sy = (*(reswd+i)).rsy ;           /* 対応したsymbolを返す     */
  354.         op = (*(reswd+i)).rop ;
  355.         return;
  356.        }
  357.       }
  358.       sy = ident;                       /* 予約語以外の時は、ident    */
  359.       op = noop;
  360. }
  361.  
  362. /**************************************/
  363. /*     innumber() : 数字の処理        */
  364. /**************************************/
  365. static void innumber(void)
  366. {
  367.   char digit[Maxdiglng+1];
  368.   csp *lvp ;
  369.   int k=0  ;
  370.   int w   ;
  371.   float realvalue ;
  372.   char *stopstring ;
  373.  
  374.      op = noop ;
  375.  
  376.      for(w=0;w<=Maxdiglng;w++)          /* null クリア                */
  377.       digit[w]='\0';
  378.  
  379.      do {
  380.       if(k < Maxdiglng) digit[k] = (char)ch ;/* 最大数字長以下の時格納*/
  381.       k++ ;
  382.       nextch() ;
  383.      } while(chartb[ch].chartp == number) ;
  384.  
  385.      if((ch != '.') && (ch != 'e') && (ch != 'E')){ /* real型でない時 */
  386.       val.ival =chtoint(k,digit) ;      /*  整数値に変換              */
  387.       return ;
  388.      }
  389.  
  390.      if(ch == '.') {                    /* 小数点の時                 */
  391.       if(k < Maxdiglng) digit[k]=(char)ch;/* 最大数字長以下の時格納   */
  392.       k++ ;
  393.       nextch() ;
  394.       period2flag = (ch == '.') ;       /* ".."                       */
  395.       rbrackflag  = (ch == ')') ;       /* ".)"  ] の代替表現         */
  396.       if(period2flag || rbrackflag) {   /* ".." または ".)" の時      */
  397.        val.ival =chtoint(k-1,digit) ;   /*  整数値に変換              */
  398.        return ;
  399.       }
  400.       if(chartb[ch].chartp != number)   /* .の次の文字が数字以外      */
  401.        pcerr(201,"") ;                  /* 実数の表記に誤りがある     */
  402.       else {
  403.        do {
  404.         if(k < Maxdiglng) digit[k] = (char)ch ;
  405.         k++ ;
  406.         nextch() ;
  407.        } while(chartb[ch].chartp == number) ;
  408.       }
  409.      }
  410.  
  411.      if((ch == 'e') || (ch == 'E')) {   /* eの時                      */
  412.       if(k < Maxdiglng) digit[k]=(char)ch;/* 最大数字長以下の時格納   */
  413.       k++ ;
  414.       nextch() ;
  415.       if((ch=='+') || (ch=='-')) {      /* e の次が+ - の時           */
  416.        if(k < Maxdiglng) digit[k]=(char)ch;/* 最大数字長以下の時格納  */
  417.        k++ ;
  418.        nextch() ;
  419.       }
  420.       if(chartb[ch].chartp != number)
  421.        pcerr(201,"") ;                  /* 実数の表記に誤り           */
  422.       else
  423.        do {
  424.         if(k < Maxdiglng) digit[k] = (char)ch ;
  425.         k++ ;
  426.         nextch() ;
  427.        } while(chartb[ch].chartp == number) ;
  428.      }
  429.  
  430.      if(k > Maxdiglng) {
  431.       pcerr(207,inttoch((long)Maxdiglng));/*数の桁数が範囲を越えている*/
  432.       strcpy(digit,"0.0");              /*  0.0 とする                */
  433.      }
  434.  
  435.      sy = realconst ;
  436.      lvp = (csp*)Malloc(sizeof(csp)) ;
  437.      lvp->cclass = real ;
  438.      val.valp = lvp ;                   /* 実数型の定数アドレスを設定 */
  439.      lvp->c.rval = (char*)Malloc(k+2);  /* 符号分、nullの2バイト分余分に確保*/
  440.      *(lvp->c.rval) = ' ' ;             /* 先頭は符号エリア           */
  441.      strcpy(lvp->c.rval+1,digit) ;      /* 転送                       */
  442.      realvalue = (float)strtod(lvp->c.rval, &stopstring) ;
  443.       /* 実数変換エラーが起きるか判定 エラーとなればsignalで登録した
  444.          エラー処理関数に飛んでいく     */
  445. }
  446.  
  447. /*****************************************/
  448. /* real_err() : 実数変換エラーの時の処理 */
  449. /*  init内のsignal関数で登録される       */
  450. /*****************************************/
  451. void real_err(int sig, int subcode)
  452. {
  453.      pcerr(208,"") ;
  454. }
  455.  
  456. /*****************************************/
  457. /* chtoint() : 文字から整数への変換処理  */
  458. /*****************************************/
  459. static long chtoint(int i,char *digit)
  460. {
  461.   long value = 0 ;
  462.   int j ;
  463.  
  464.      sy = intconst ;                    /* 整数とする                 */
  465.      if(i > Maxdiglng) {
  466.       pcerr(207,inttoch((long)Maxdiglng));/*数の桁数が範囲を越えている*/
  467.       return(0L) ;
  468.      }
  469.      for(j=0;j<i;j++)                   /* 文字を整数に変換           */
  470.       if(value <= (Maxint - (digit[j]-'0')) / 10  ) /* 上限チェック   */
  471.        value = value*10 + (digit[j]-'0') ;
  472.       else {
  473.        pcerr(203,inttoch(Maxint)) ;     /* 符号なし整数がmaxintより大きい*/
  474.        return(0L)        ;
  475.       }
  476.      return(value) ;
  477. }
  478.  
  479. /**************************************/
  480. /*     strings() : 文字列の処理       */
  481. /**************************************/
  482. static void strings(void)
  483. {
  484.   char string[Maxstrlng+1] ;
  485.   char *heapstring ;
  486.  
  487.      lgth = 0 ;
  488.      sy   = stringconst ;
  489.      op   = noop ;
  490.  
  491.      do {
  492.       do {
  493.        nextch() ;
  494.        if(lgth<Maxstrlng) string[lgth]=(char)ch;/* 最大文字列長以下の時格納 */
  495.        lgth++ ;
  496.       } while((!eolnflag) && (ch != '\'')) ;
  497.       if(eolnflag) pcerr(202,"") ;      /* 文字列定数は行を越えてはならない */
  498.       else nextch() ;                   /* 'の時、次の文字を読む             */
  499.      } while(ch == '\'') ;              /* 'が2続くときはもう一度繰り返す   */
  500.  
  501.      lgth-- ;                           /* 最後の'を取り除く                */
  502.      if(lgth==0) pcerr(205,"") ;        /* 文字長0の文字列は許されない      */
  503.      else if(lgth == 1)
  504.       val.ival = (long)string[0];       /* 1文字の時は、その値をvalに入れる */
  505.      else {                             /* 2文字以上の時                    */
  506.       val.valp = (csp*)Malloc(sizeof(csp)) ;
  507.       val.valp->cclass = strg ;
  508.       if(lgth > Maxstrlng) {            /* 最大文字列長を越えている時       */
  509.        pcerr(602,inttoch((long)Maxstrlng)) ; /* 文字列の最大長を越えている  */
  510.        lgth = Maxstrlng ;               /* 最大文字列長までを有効とする     */
  511.       }
  512.       string[lgth] = '\0' ;             /* nullで終わる文字列とする         */
  513.       heapstring = (char*)Malloc(lgth+1) ;/* 文字列長分のエリアを確保       */
  514.       strcpy(heapstring,string) ;
  515.       val.valp->c.sval = heapstring ;
  516.      }
  517. }
  518.  
  519. /**************************************/
  520. /*     colonch() : :(コロン) の処理      */
  521. /**************************************/
  522. static void colonch(void)
  523. {
  524.      op = noop;
  525.      nextch();
  526.      if(ch == '=') {                    /* ':='                       */
  527.       sy = becomes;                     /*   becomes  と する         */
  528.       nextch();
  529.      }
  530.      else sy = colon ;                  /* ':'  colon と する         */
  531. }
  532.  
  533. /**************************************/
  534. /*     lparch() : ( の処理            */
  535. /**************************************/
  536. static void lparch(void)
  537. {
  538.      op = noop   ;
  539.      nextch();
  540.      if(ch == '*') skipcomment();       /* '(*'   注釈                */
  541.      else if(ch == '.') {               /* '(.'   [ の代替表現        */
  542.       nextch()    ;
  543.       sy = lbrack ;
  544.      }
  545.      else  sy = lparent;
  546. }
  547.  
  548. /**************************************/
  549. /*     rparch() : ) の処理            */
  550. /**************************************/
  551. static void rparch(void)
  552. {
  553.      op = noop;
  554.      nextch();
  555.      if(rbrackflag) {                   /* 数字処理中 ".)"を見つけた時*/
  556.       sy = rbrack  ;                    /* 数字処理中 .. を見つけた時 */
  557.       rbrackflag = false ;
  558.      }
  559.      else sy = rparent;
  560. }
  561.  
  562. /*******************************************/
  563. /* skipcomment() : コメントの読み飛ばし処理*/
  564. /*    *) または } がコメントの終わり       */
  565. /*        ただし } は、シフトJISの2バイト目*/
  566. /*          になり得るので、その処理もする */
  567. /*******************************************/
  568. static void skipcomment(void)
  569. {
  570.   boolean endflag ;
  571.  
  572.      nextch();
  573.      if(ch=='$') options();             /* $の後にはオプション が来る     */
  574.      do {
  575.       while(iskanji(ch)) {              /* シフトJIS1コード1バイト目の時   */
  576.        nextch() ;                       /* 2文字分読み飛ばし          */
  577.        nextch() ;
  578.       }
  579.       if(ch=='*') {
  580.        nextch() ;
  581.        endflag=((ch==')')||(ch=='}')) ; /*   *) または }             */
  582.       }
  583.       else {
  584.        endflag = (ch == '}') ;          /*   }  でコメント終わり      */
  585.        if(!endflag) nextch() ;
  586.       }
  587.      } while(!endflag) ;
  588.      nextch()  ;
  589.      insymbol();                        /* 有効なsymbolを見つける(再帰)*/
  590. }
  591.  
  592. /*****************************************/
  593. /* options() : オプション設定処理        */
  594. /*             d+ d- t+ t-               */
  595. /*****************************************/
  596. static void options(void)
  597. {
  598.   char optionchar ;
  599.  
  600.      nextch() ;
  601.      optionchar = (char)ch ;
  602.      if((ch=='d') || (ch=='t')) nextch();
  603.      else return ;
  604.      if((ch=='+') || (ch=='-'))
  605.       if(optionchar=='d') debug = (ch=='+') ;
  606.       else
  607.        if(ch=='+') genp(iTRA,1) ;       /* トレースオン  tra  1       */
  608.        else        genp(iTRA,2) ;       /* トレースオフ  tra  2       */
  609. }
  610.  
  611. /****************************************/
  612. /* periodch() :  .(ピリオド)の処理        */
  613. /****************************************/
  614. static void periodch(void)
  615. {
  616.      op = noop;
  617.      nextch();
  618.      if(period2flag) {
  619.       sy = period2 ;                    /* 数字処理中 .. を見つけた時 */
  620.       period2flag = false ;
  621.      }
  622.      else if(ch == '.') {               /* 今 .. だった時             */
  623.        sy = period2 ;                   /* ..  と する                */
  624.        nextch();
  625.      }
  626.      else if(ch == ')') {               /* 今 .) だった時             */
  627.       sy = rbrack ;                     /*  ]   とする                */
  628.       nextch()    ;
  629.      }
  630.      else sy = period ;                 /* . 単独の時は . とする      */
  631. }
  632.  
  633. /****************************************/
  634. /*        ltch() :  < の処理            */
  635. /****************************************/
  636. static void ltch(void)
  637. {
  638.      nextch();
  639.      sy=relop;
  640.      if(ch == '=') {                    /* '<='                       */
  641.       op = leop;                        /*       less equal と する   */
  642.       nextch();
  643.      }
  644.      else if(ch == '>') {               /* '<>'                       */
  645.       op = neop ;                       /*       not equal  と する   */
  646.       nextch()  ;
  647.      }
  648.      else op = ltop ;                   /* '<'   less than とする     */
  649. }
  650.  
  651. /****************************************/
  652. /*        gtch() :  > の処理            */
  653. /****************************************/
  654. static void gtch(void)
  655. {
  656.      nextch();
  657.      sy = relop;
  658.      if(ch == '=') {                    /* '>='                       */
  659.       op = geop;                        /*   grater equal と する     */
  660.       nextch();
  661.      }
  662.      else op = gtop ;                   /* '>'  grater than とする    */
  663. }
  664.  
  665. /****************************************/
  666. /*      specialtch() : 特殊文字の処理   */
  667. /****************************************/
  668. static void specialch(void)
  669. {
  670.      sy = chartb[ch].ssy ;              /* その文字のsymbol           */
  671.      op = chartb[ch].sop ;              /* その文字の演算子           */
  672.      nextch()            ;
  673. }
  674.  
  675. /****************************************/
  676. /*        illegch() : 不当文字の処理    */
  677. /****************************************/
  678. static void illegch(void)
  679. {
  680.   char wch[3] ;
  681.  
  682.      sy = othersy;
  683.      op = noop   ;
  684.      wch[0] = (char)ch ;
  685.      if(iskanji(ch)) {                  /* 漢字の時 漢字埋め込み処理  */
  686.       nextch() ;
  687.       wch[1] = (char)ch   ;
  688.       wch[2] = '\0' ;
  689.      }
  690.      else wch[1] = '\0' ;
  691.      pcerr(30,wch)      ;               /* 不当文字が現れた           */
  692.      nextch()           ;
  693. }
  694.